function checkBarcode()
{
	var barcode = document.getElementById("barcode").value;

	if ("" == barcode || barcode.length > 45)
	{
		alert("barcode is illegal");
		document.getElementById("barcode").focus();
		return false;
	}
	if (!/^\d+$/.test(barcode)) 
	{
		alert('barcode is illegal,number is ok');
		return false;
	}
	backIns(barcode);
}
function backIns(barcode) 
{
	
	var xmlHttp = null;
	if (window.ActiveXObject) 
	{
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else if (window.XMLHttpRequest) 
	{
		xmlHttp = new XMLHttpRequest();
	} else 
	{
		alert("ajax won't show in your web browser");
		return;
	}

	xmlHttp.open("GET", "ReturnServlet?barcode=" + barcode, true);

	xmlHttp.onreadystatechange = function()
	{
	    if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
		{
	    	var login=/<script>/ig;
	    	if(login.test(xmlHttp.responseText))
	    	{
	    		eval("top.location.href='/lab/login.jsp'");
	    		return;
	    	}
			var contentType = xmlHttp.getResponseHeader("Content-Type");
			if (contentType == "text/html") 
			{
				var message = xmlHttp.responseText;
				document.getElementById("message").innerHTML= message;
				document.getElementById("firstname").value = "";
				document.getElementById("lastname").value =  "";
				document.getElementById("gender").value = "";
				document.getElementById("email").value =  "";
				document.getElementById("loan").value =  "";
				
				document.getElementById("insname").innerHTML= eval("&nbsp;");
				document.getElementById("userID").innerHTML= eval("&nbsp;");
				document.getElementById("borrowtime").innerHTML= eval("&nbsp;");
				document.getElementById("sbacktime").innerHTML= eval("&nbsp;");
				document.getElementById("backtime").innerHTML= eval("&nbsp;");
			}
			if (contentType == "application/json")
			{
				var jsonObj = eval('(' + xmlHttp.responseText + ')');
				document.getElementById("barcode").value = jsonObj.barcode;
				document.getElementById("firstname").value = jsonObj.firstname;
				document.getElementById("lastname").value = jsonObj.lastname;
				document.getElementById("gender").value = jsonObj.gender;
				document.getElementById("email").value = jsonObj.email;
				document.getElementById("prompt").value = jsonObj.loan;
				
				document.getElementById("insname").innerHTML= jsonObj.insName;
				document.getElementById("userID").innerHTML= jsonObj.userID;
				document.getElementById("borrowtime").innerHTML= jsonObj.borrowDate;
				document.getElementById("sbacktime").innerHTML= jsonObj.SBackDate;
				document.getElementById("backtime").innerHTML= jsonObj.backDate;
				document.getElementById("message").innerHTML= "SUCCESS";
			}
		} 
		else 
		{
			document.getElementById("message").innerHTML= "doing...";
		}
	}
	xmlHttp.send(null);

}